//
// Created by liutp on 2022/6/19.
//

#include <cstdio>
#include <malloc.h>
#include <cstring>
#include "type.h"
#include "util.h"

 int read_file(const char *fileName, Buffer* buf) {
    //const char *fileName = "ani.webm"; //"myData.h264";
    printf("读取文件  %s \n", fileName);
    FILE *finput = fopen(fileName, "rb");
    fseek(finput, 0L, SEEK_END);
    buf->size = (u32) ftell(finput);
    // rewind(finput);
    fseek(finput, 0L, SEEK_SET);

    buf->data = (u8 *) malloc(sizeof(u8) * buf->size);
    // memset(buf->data, 1, sizeof(u8) * buf->size);
    buf->size = fread(buf->data, sizeof(u8), buf->size, finput);
    fclose(finput);
    printf("文件大小 %d \n", buf->size);
    buf->pos = buf->data;
    buf->end = buf->data + buf->size;

    return 0;
}